package org.zhouhe.security;

import java.util.HashSet;
import java.util.Set;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.zhouhe.service.UserService;

public class UserDetailsServiceImpl implements UserDetailsService{

	private Logger log = Logger.getLogger(getClass());
	@Autowired
	private UserService userService;
	
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		log.debug("UserDetailsServiceImpl.loadUserByUsername(..), userService="+ userService);
		
		return getMockData();
	}

	private UserDetails getMockData(){
		boolean enabled = true;
		boolean accountNonExpired = true;
		boolean credentialsNonExpired = true;
		boolean accountNonLocked = true;
		
		Set<GrantedAuthority> grantedAuths = new HashSet<GrantedAuthority>();
		grantedAuths.add(new SimpleGrantedAuthority("ROLE_EIPP"));
		
		UserDetails ud = new User("zhouhe", "123456", enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, grantedAuths);
		
		return ud;
	}
}
